{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "思考1：输入一个包含若干整数的字符串，并输出字符串中的最大值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入任意若干整数字符串11,22,55\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "55"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = input(\"输入任意若干整数字符串\")\n",
    "max(eval(data))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个包含若干整数的字符串：13,123\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "123"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "lst = eval(input(\"请输入一个包含若干整数的字符串：\"))\n",
    "max(lst)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "思考2：输入一个包含若干整数的列表，输出由其中的偶数组成的新列表。要求用列表推倒式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个包含若干整数的列表111,555,444,333\n",
      "[444]\n"
     ]
    }
   ],
   "source": [
    "data = eval(input('请输入一个包含若干整数的列表'))\n",
    "print([num for num in data if num%2==0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "思考3：求出列表['abc','1234','python']中各个元素的长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 4, 6]\n"
     ]
    }
   ],
   "source": [
    "lis = ['abc','1234','python']\n",
    "print(list(map(len,lis)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "思考4:编写1—100的和，用reduce()函数操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5050"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from functools import reduce\n",
    "from operator import add\n",
    "reduce(add,(range(101)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "思考5:列表[10,20,30,40,50]中每个元素加2，用lambda表达式操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[12, 22, 32, 42, 52]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lis = [10,20,30,40,50]\n",
    "func = lambda x: x+2\n",
    "list(map(func,lis))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "思考6:生成包含两个或三个汉字的人名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.1348953069014518\n",
      "李雪\n"
     ]
    }
   ],
   "source": [
    "from random import choice,random\n",
    "name=choice('董孙李周赵钱')\n",
    "a=random()\n",
    "if a >0.5:\n",
    "    name +=choice('付煜艳延子凯')\n",
    "name +=choice('国栋含雪玲端')\n",
    "print(a)\n",
    "print(name) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "思考7：序号1-52的同学为1901班，序号53-105的同学为1902班，序号106-159的同学为1903班"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1903\n"
     ]
    }
   ],
   "source": [
    "def classNum(i):\n",
    "    if (i<53):\n",
    "        classid='1901';\n",
    "    elif(53<=i<105):\n",
    "        classid='1902';\n",
    "    else:\n",
    "        classid='1903';\n",
    "    print(classid)\n",
    "classNum(158)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
